import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { DeleteResult, Repository, UpdateResult } from 'typeorm';
import { Bk_Course_Category } from './bk_course_category.entity';

@Injectable()
export class CourseCategoryService {
    constructor(
        @InjectRepository(Bk_Course_Category)
        private readonly courseCategoryRepository: Repository<Bk_Course_Category>
    ) { }

    async add(courseCategory: { category_name: string }): Promise<Bk_Course_Category> {
        return await this.courseCategoryRepository.save(courseCategory);
    }

    async delete(id: number): Promise<DeleteResult> {
        return await this.courseCategoryRepository.delete(id);
    }

    async update(id: number, courseCategory: { category_name: string }): Promise<UpdateResult> {
        return await this.courseCategoryRepository.update(id, courseCategory);
    }

    async findAll(query: any): Promise<[Bk_Course_Category[], number]> {
        return await this.courseCategoryRepository.findAndCount({ order: { id: "ASC" }, skip: query.skip, take: query.take });
    }
}